package org.zcl.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.zcl.entity.UserInfo;
import org.zcl.mapper.UserInfoMapper;
import org.zcl.model.ApiResponse;
import org.zcl.model.vo.UserInputVo;
import org.zcl.service.UserInfoService;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author zcl
 * @since 2021-11-25
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    @Override
    public ApiResponse addUser(UserInputVo userVo) {
        UserInfo userInfo = new UserInfo();
        BeanUtils.copyProperties(userVo, userInfo);
        int result = baseMapper.insert(userInfo);
        String code = "0";
        String msg = "success";
        if (result != 1) {
            code = "-1";
            msg = "fail";
        }
        return ApiResponse.builder()
                .code(code)
                .data(userInfo)
                .msg(msg)
                .build();
    }
}
